﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iShoppingDTO;

namespace iShoppingDAO
{
    public class SanPham_MultiDAO
    {
        public static int LayMaSanPham_Multi()
        {
            string selectCommand = "Select max(MaChiTietMT) From SanPham_Multimedia";
            int num = 0;
            try
            {
                num = (int)DataProvider.ExecuteScalar(selectCommand);
            }
            catch (Exception)
            {
            }
            num++;
            return num;
        }

        public static bool AddSanPham_Multi(SanPham_MultiDTO info)
        {
            int firstcode = LayMaSanPham_Multi();
            try
            {
                info.MaMT = firstcode;
                string sql = string.Format("insert into SanPham_Multimedia VALUES('{0}', '{1}', '{2}')",
                info.MaChiTietMT, info.MaSanPham, info.MaMT);
                DataProvider.ExecuteNoneQuery(sql);
                return true;
            }
            catch (Exception e)
            {

            }
            return false;
        }

        public static bool AddSanPham_Multi(List<SanPham_MultiDTO> list_info)
        {
            int firstcode = LayMaSanPham_Multi();
            try
            {
                foreach (SanPham_MultiDTO info in list_info)
                {
                    info.MaChiTietMT = firstcode;
                    string sql = string.Format("insert into SanPham_Multimedia VALUES({0}, '{1}', {2})",
                    info.MaChiTietMT, info.MaSanPham, info.MaMT);
                    DataProvider.ExecuteNoneQuery(sql);

                    firstcode++;
                }
                return true;
            }
            catch (Exception e)
            {

            }
            return false;
        }
    }
}
